package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("品牌列表")
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTradeMarkController {

    //调用远程方法
    @Autowired
    private BaseTrademarkService baseTrademarkService;


    //查询数据
    @GetMapping("{page}/{limit}")
    public Result getTradeMarkPage(@PathVariable Long page,
                                   @PathVariable Long limit){
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page,limit);
            //调用方法
            IPage iPage= baseTrademarkService.getTradeMarkPage(baseTrademarkPage);

        return  Result.ok(iPage);
    }
     //添加保存数据
    @ApiOperation(value = "新增BaseTrademark")
    @PostMapping("save")
    public  Result aveBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();

    }

    //删除数据
    @ApiOperation(value = "删除BaseTrademark")
    @DeleteMapping("remove/{id}")
    public  Result remove(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();

    }

    //  根据Id 获取数据！
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        //  调用方法 ：
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    //修改数据
    @ApiOperation(value = "修改BaseTrademark")
    @PutMapping("update")
        public Result updateById(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }




}
